package Thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class WebDownload extends Thread{
    private String url;
    private String name;

    class WebDownloader{
        public void download(String url,String name){
            try {
                FileUtils.copyURLToFile(new URL(url),new File(name));
            } catch (IOException e) {
                System.out.println("下载器出现故障...");
                e.printStackTrace();
            }
        }
    }

    WebDownload(String url,String name){
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        WebDownloader webDownloader = new WebDownloader();
        webDownloader.download(url,name);
        System.out.println("下载了："+name);
    }

    public static void main(String[] args) {
        WebDownload t1 = new WebDownload("https://www.kuangstudy.com/assert/course/c1/01.jpg","1.jpg");
        WebDownload t2 = new WebDownload("https://www.kuangstudy.com/assert/course/c1/02.jpg","2.jpg");
        WebDownload t3 = new WebDownload("https://www.kuangstudy.com/assert/course/c1/03.jpg","3.jpg");
        t1.start();
        t2.start();
        t3.start();
    }
}

